﻿using System.Linq.Expressions;

namespace Fuse8.ContentManagementFramework.BizFacade.Services.Contents.Queryable
{
    public class JoinKeyVisitor : ExpressionVisitor
    {
        private string fieldName;

        public string GetFieldName(Expression expression)
        {
            Visit(expression);
            return fieldName;
        }

        protected override Expression VisitConstant(ConstantExpression node)
        {
            fieldName = node.GetValueFromConst<string>();
            return base.VisitConstant(node);
        }

        protected override Expression VisitMember(MemberExpression node)
        {
            fieldName = node.Member.Name;
            return base.VisitMember(node);
        }
    }
}